package com.annoncesautomobile.vue.rechercheAnnonce;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.annoncesautomobile.R;
import com.annoncesautomobile.modele.util.Requete;
import com.annoncesautomobile.vue.SuperActivity;

public class ChoixDescriptifActivity extends SuperActivity {

	private EditText divCommentaire; 
	private Requete request;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.activity_choix_descriptif);
		
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
		TextView textViewActivityTitleText = (TextView) findViewById(R.id.activity_title_text);
		textViewActivityTitleText.setText(getString(R.string.title_activity_choix_descriptif));
		
		addBoutonBas();
		
		this.divCommentaire = (EditText) findViewById(R.id.TextDescriptif);
		this.request = (Requete) getIntent().getParcelableExtra("requete");
		if(this.request.get("descriptif") != null && !this.request.get("descriptif").equals(""))
		{
			this.divCommentaire.setText(this.request.get("descriptif"));
		}
		else
		{
			this.divCommentaire.setHint("Saisir le descriptif de votre annonce");
		}
		Button b = (Button) findViewById(R.id.btnValiderDescriptif);
		b.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				Intent output = new Intent();
				
				String descriptif = getDescriptif();
				int size = descriptif.length();
				int max = Math.min(size, 15);
				String display = descriptif.substring(0,max);
				if(display.length()> 0)
				{
					display = display.replaceAll("\n", "-");
				}
				request.put("descriptif", getDescriptif(),display);
				output.putExtra("requete", (Parcelable) request);
				setResult(RESULT_OK, output);
				finish();
			}
		});
	}

	public String getDescriptif()
	{
		return this.divCommentaire.getText().toString();
	}
	
	public void onBackPressed(View view) {
		this.onBackPressed();
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
	}
}
